package com.itheima.demo;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo_HashMap001 {
    public static void main(String[] args) {
        //创建一个hashmap集合;
        HashMap<String, Integer> map = new HashMap<>();
        map.put("aaa", 11);
        map.put("bbb", 22);
        map.put("ccc", 33);
        map.put("ddd", 44);
        map.put("eee", 55);
        //遍历键值对集合;
        //方式一:
        Set<String> s = map.keySet();
        //遍历s;
        for (String key : s) {
            Integer value = map.get(key);
            System.out.println(key + " = " + value);
        }

        System.out.println("=============================");

        //方式二:
        Set<Map.Entry<String, Integer>> s1 = map.entrySet();
        for (Map.Entry<String, Integer> s2 : s1) {
            String key = s2.getKey();
            Integer value = s2.getValue();
            System.out.println(key+" = "+value);
        }
    }
}
